﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<link href="~/Areas/Admin/Content/docs.css" rel="stylesheet" />
<script src="~/Areas/Admin/Content/plupload/moxie.min.js"></script>
@*<script src="~/Areas/Admin/Content/plupload/plupload.min.js"></script>*@
<script src="~/Areas/Admin/Content/plupload/plupload.dev.js"></script>
<div id="imgdiv"></div>
<div id="filelist"></div>
<div id="container">
    <a id="pickfiles" href="javascript:void(0)">[Select files]</a>
    <a id="uploadfiles" href="javascript:void(0)">[Upload files]</a>
</div>
<br />
<pre id="console"></pre>
<div id="list1"></div>
<script type="text/javascript">
    var List = BUI.List

    var items = 
      tpl = [
        '<li class="bui-list-item">',
          '<div class="img-list-content">',
            '<a class="img-list-link" href="{href}">',
              '<img src="{src}"/>',
            '</a>',
            '<div class="img-list-des">',
              '<div>标题：<input type="text" value="{title}"/><span class="x-icon x-icon-mini x-icon-hover img-list-item-close">×</span></div>',
              '<div class="img-list-pro">描述：<textarea class="img-list-item-des">{desc}</textarea></div>',
              '<div>排序：<input type="text" value="{sort}"/></div>',
            '</div>',
          '</div>',
          '<div class="img-list-border">',
          '</div>',
        '</li>'
      ];
    list = new List.SimpleList({
        render: '#list1',
        elCls: 'img-list clearfix',
        items: [],
        itemTpl: tpl.join('')
    });
    list.render();
    //setTimeout(function () {
    //    list.addItem({
    //        title: '菜单2',
    //        sort: '1',
    //        href: 'javascript:void(0);',
    //        src: '',
    //        desc: '<p>分为右键菜单，弹出菜单，左侧菜单以及各种自定义的菜单</p>'
    //    });
    //},5000)
    var uploader = new plupload.Uploader({
        runtimes: 'flash',
        browse_button: 'pickfiles', // you can pass in id...
        //container: document.getElementById('container'), // ... or DOM Element itself
        url: "../AjaxUploadFile",
        filters: {
            max_file_size: '10mb',
            mime_types: [
                { title: "Image files", extensions: "jpg,jpeg,gif,png" },
                { title: "Zip files", extensions: "zip,rar" }
            ]
        },
        flash_swf_url: 'http://rawgithub.com/moxiecode/moxie/master/bin/flash/Moxie.cdn.swf',
        //silverlight_xap_url: 'http://rawgithub.com/moxiecode/moxie/master/bin/silverlight/Moxie.cdn.xap',
        init: {
            PostInit: function () {
                document.getElementById('filelist').innerHTML = '';
                document.getElementById('uploadfiles').onclick = function () {
                    uploader.start();
                    return false;
                };
            },
            FilesAdded: function (up, files) {
                uploader.start();
                //var file = files[0];
                //var img = new o.Image();
                //img.onload = function () {
                //    img.embed($('#imgdiv')[0], {
                //        width: 100,
                //        height: 60,
                //        crop: true,
                //        swf_url: o.resolveUrl(up.settings.flash_swf_url),
                //        xap_url: o.resolveUrl(up.settings.silverlight_xap_url)
                //    });
                //};
                //img.load(file.getSource());
            },
            UploadProgress: function (up, file) {
                //document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
            },
            FileUploaded: function (up, file, info) {
                debugger;
                var res = '{}';
                if (info.response == null) {
                    var headers = info.responseHeaders.split('\r\n');
                    $.each(headers, function (n, item) {
                        if (item && item.split(':')[0] == 'res') {
                            res = eval('(' + item.split(':')[1] + ')');
                        }
                    })
                } else {
                    res = eval('(' + info.response + ')');
                }
                if (res.result == true) {
                    list.addItem({
                        title: '',
                        sort: '0',
                        href: 'javascript:void(0);',
                        src: '/File/' + res.id,
                        desc: ''
                    });
                } else {
                    alert(decodeURI(res.msg));
                }
            },
            Error: function (up, err) {
                //document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
            }
        }
    });
    uploader.init();

</script>
